﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DataCentral.UserControls;
using DevExpress.XtraEditors;
using System.Windows.Forms;
using DataCentral.Forms;
using CommonData;

namespace DataCentral.UsecaseControllers
{
    public partial class MainUsecase
    {
        private void AddControl(CommonCenterControl control, string strCaption)
        {
            _FRMMain.CenterGroup.Controls.Clear();
            _FRMMain.CenterGroup.Controls.Add(control);
            control.Dock = DockStyle.Fill;
            _FRMMain.CenterGroup.Text = strCaption;
        }

        private void AddControlToCenterGroup(CommonCenterControl control, string strCaption)
        {
            if (_FRMMain.CenterGroup.Controls.Count > 0)
            {
                CommonCenterControl preControl = (CommonCenterControl)_FRMMain.CenterGroup.Controls[0];
                if (!preControl.Name.Equals(control.Name))
                {
                    if (preControl.IsDataChanged)
                    {
                        DialogResult dlgResult = MessageClass.ShowQuestionMessage(ConstantClass._Question_DataChanged);
                        if (dlgResult == DialogResult.Yes)
                        {
                            preControl.SaveDataOnControl();
                            AddControl(control, strCaption);
                        }
                        else if (dlgResult == DialogResult.No)
                        {
                            AddControl(control, strCaption);
                        }
                    }
                    else
                    {
                        AddControl(control, strCaption);
                    }
                }
            }
            else
            {
                AddControl(control, strCaption);
            }
        }

        public void ShowUserMaintenance()
        {
            UserMaintenanceForm frmUserMaintenance = new UserMaintenanceForm();
            frmUserMaintenance.ShowDialog();
        }

        public void ShowRoleMaintenance()
        {
            RoleMaintenanceForm frmRoleMaintenance = new RoleMaintenanceForm();
            frmRoleMaintenance.ShowDialog();
        }

        internal void ShowWorldTimeForm()
        {
            TimeZoneTool frmTimeZone = new DataCentral.Forms.TimeZoneTool();
            frmTimeZone.ShowDialog();
        }

        internal void ShowExceptionManagement()
        {
            ManageExceptionForm frmException = new ManageExceptionForm();
            frmException.ShowDialog();
        }

        internal void ShowModuleMaintenanceControl()
        {
            ModuleMaintenanceForm frmModule = new ModuleMaintenanceForm();
            frmModule.ShowDialog();
        }

        internal void ShowAccessRightForm()
        {
            AccessRightUsecase ucAccessRight = new AccessRightUsecase(_UserBO);
            ucAccessRight.StartUsecase();
        }

        internal void ShowConfigAutoSendMailForm()
        {
            MailConfigurationUsecase ucMailConfiguration = new MailConfigurationUsecase();
            ucMailConfiguration.StartUsecase();
        }

        internal void ShowConfigDatabaseForm()
        {
            SQLConnectionForm frmSQLConnection = new SQLConnectionForm();
            frmSQLConnection.ShowDialog();
        }

        internal void ShowDatabaseConfigurationControl()
        {
            DatabaseConfigControl ctDatabaseConfiguration = new DatabaseConfigControl();
            AddControlToCenterGroup(ctDatabaseConfiguration, "Cấu hình cơ sở dữ liệu ngành hàng");
        }

        internal void ShowSynchronizeControl()
        {
            TablesConfigControl ctTablesConfig = new TablesConfigControl();
            AddControlToCenterGroup(ctTablesConfig, "Quản lí đồng bộ dữ liệu");
        }

        internal void ShowAfterSyncForm()
        {
            AfterSyncMasterForm frmAfterSync = new AfterSyncMasterForm(string.Empty);
            frmAfterSync.ShowDialog();
        }

        internal void ShowSaleTeamControl()
        {
            SaleTeamControl ctSaleTeam = new SaleTeamControl();
            AddControlToCenterGroup(ctSaleTeam, "Quản lí danh sách đội bán hàng");
        }

        internal void ShowAssignSalePersonControl()
        {
            AssignSalePersonControl ctAssignSalePerson = new AssignSalePersonControl();
            AddControlToCenterGroup(ctAssignSalePerson, "Phân đội nhân viên");
        }

        internal void ShowEditSalePersonControl()
        {
            EditSalePersonControl ctEditSalePerson = new EditSalePersonControl();
            AddControlToCenterGroup(ctEditSalePerson, "Điều chỉnh nhân viên");
        }

        internal void ShowAssignRouteControl()
        {
            EditSaleRouteDetailControl ctEditSaleRouteDetail = new EditSaleRouteDetailControl();
            AddControlToCenterGroup(ctEditSaleRouteDetail, "Điều chỉnh tuyến bán hàng cho nhân viên");
        }

        internal void ShowEditSaleOrderControl()
        {
            EditSaleOrdersControl ctEditSaleOrder = new EditSaleOrdersControl();
            AddControlToCenterGroup(ctEditSaleOrder, "Điều chỉnh đơn hàng sau đồng bộ");
        }

        internal void ShowEditSaleOrderDetailControl()
        {
            EditSaleOrderDetailControl ctEditSaleOrderDetail = new EditSaleOrderDetailControl();
            AddControlToCenterGroup(ctEditSaleOrderDetail, "Điều chỉnh đơn hàng chi tiết sau đồng bộ");
        }


        internal void ShowConvertSaleOrderControl()
        {
            ConvertSaleOrderControl ctConvertSaleOrder = new ConvertSaleOrderControl();
            AddControlToCenterGroup(ctConvertSaleOrder, "Chuyển đổi dữ liệu bán hàng vào hệ thống");
        }

        internal void ShowSalePersonDebtControl()
        {
            SalePersonDebtControl ctSalePersonDebt = new SalePersonDebtControl();
            AddControlToCenterGroup(ctSalePersonDebt, "Quản lý công nợ - Thu nợ");
        }


        internal void ShowDebtAdjustControl()
        {
            DebtAdjustControl ctDebtAdjust = new DebtAdjustControl();
            AddControlToCenterGroup(ctDebtAdjust, "Quản lý thu nợ");
        }

        internal void ShowPerformDebtForm()
        {
            DebtAdjustForm frmDebtAdjust = new DebtAdjustForm();
            frmDebtAdjust.ShowDialog();
        }
    }
}
